#include "WProgram.h"
#include <string.h>
#include "SongManager.h"

/**
 * Utility Library Implementation for Party Sense Application
 *
 * Authors:
 * Arjun Sinha
 * Rajeev Krithivasan
 * Will Sergeant
 **/

SongManager::SongManager(){
	_numSongs = 0;
}

int SongManager::getNumSongs(){
	return _numSongs;
}

Song SongManager::getNextSong(){
	int maxVal = _songs[0].getPhoneCount() - songs[0].getPlayCount();
	Song maxS = _songs[0];

	for (int i = 0; i < _numSongs; i++){
		int songVal = (_songs[i].getPhoneCount() - _songs[i].getPlayCount());
		if (songVal > maxVal){
			maxVal = songVal;
			maxS = _songs[i];
		}
	}

	return maxS;
}

void SongManager::addSong(Phone p, String s){
	String artist = string::strtok(s, "*");
	String title = string::strtok(NULL, "*");
	_songs[_numSongs] = Song(title, artist, p);
	_numSongs++;
}

void SongManager::addAllSongs(Phone p, String sList){
	String nextStr = string::strtok(sList, "|");
	while (nextStr != NULL && _numSongs < MAX_SONG_LIST_LEN){
		addSong(p, nextStr);
		nextStr = string::strtok(NULL, "|");
	}
};
		

//boolean SongManager::resize();
